<template>
  <!--出差-->
  <div class="bus">
    <!--出差查找-->
    <el-row>
      <span style="padding: 0 10px"><i class="font-14 el-icon-s-open"></i></span>
      <el-select v-model="filterValue" @change="initData(currPage,pageSize,filterValue,vagueValue,content)" placeholder="全部数据" style="width: 120px">
        <el-option v-for="item in filterOptions" :key="item.value"
                    :label="item.label" :value="item.value">
        </el-option>
      </el-select>
      <span style="padding: 0 10px 0 30px"><i class="fn el-icon-message-solid"></i></span>
      <el-input v-model="content" clearable placeholder="请输入内容" style="width: 150px"></el-input>
      <el-select v-model="vagueValue" @change="initData(currPage,pageSize,filterValue,vagueValue,content)" placeholder="出差主题" style="width: 120px">
        <el-option v-for="item in vagueOptions" :key="item.value"
                   :label="item.label" :value="item.value">
        </el-option>
      </el-select>
      <el-button @click="initData(currPage,pageSize,filterValue,vagueValue,content)" icon="el-icon-search" size="small" circle></el-button>
    </el-row>
    <!--新建出差-->
    <el-row style="margin-top: 15px">
      <el-col :span="12">
        <span>出差</span>
        <small class="text-muted font-13">共{{totalSize}}条</small>
      </el-col>
      <el-col :span="12" class="text-right">
        <el-button type="text" @click="dialogFormVisible = true">
          <el-button size="small" icon="el-icon-circle-plus-outline">新建</el-button>
        </el-button>
      </el-col>
      <!--出差dialog-->
      <el-dialog title="出差" :visible.sync="dialogFormVisible" width="60%" @open="openDialog" @close="closeDialog" style="color: #333333"  >
        <el-form ref="bus" :model="business" label-width="100px" :rules="rules">
          <el-divider></el-divider>
          <el-row>
            <el-col>
              <el-form-item label="主题:" prop="businessTheme">
                <el-input v-model="business.businessTheme" style="width: 91%"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="开始时间:" >
                <el-date-picker v-model="business.businessStartDate" type="date" placeholder="任意时间点" style="width: 79%">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="结束时间:">
                <el-date-picker v-model="business.businessEndDate" type="date" placeholder="任意时间点" style="width: 79%">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col style="line-height: 40px">
              <el-form-item label="目的地:">
                <el-input v-model="business.businessDestination" style="width: 91%"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label="交通工具:">
                <el-select v-model="business.businessVehicle" placeholder="未选" style="width: 91%">
                  <el-option v-for="item in jtOptions" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label="客户:" prop="customerByCustomerId.customerName">
                <el-input :disabled="true" v-model="business.customerByCustomerId.customerName" style="width: 91%"></el-input>
              </el-form-item>
              <div class="form-inline" v-show="customerBoxShow">
                <el-input v-model="customerValue" clearable size="medium" placeholder="拼音.字母.关键字" style="width: 20%"></el-input>
                <el-button @click="findCustomer" size="medium" icon="el-icon-search"></el-button>
                <el-popover placement="top" v-model="visible">
                  <div style="margin-bottom: 10px">
                    <span>查询条件:{{customerValue}}</span>
                    <span @click="cleanCustomer" class="cursor" style="float: right"><i class="el-icon-error"></i></span>
                  </div>c
                  <ul class="cu-ul" v-if="customerList2 !== ''">
                    <li @click="choiceCustomer2(item)" v-for="item in customerList2">{{item.customerName}}</li>
                  </ul>
                  <div style="margin: 5px 0;text-align: center" v-if="customerList2 == ''">
                    <i class="el-icon-warning-outline"/>没有符合条件的客户！
                  </div>
                </el-popover>
                <el-tooltip class="item" effect="dark" content="浏览选择客户" placement="bottom">
                  <el-button @click="innerVisible(cusCurrPage,cusPageSize)" size="medium" icon="el-icon-s-operation"></el-button>
                </el-tooltip>
              </div>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label="借款:" prop="businessMoney">
                <el-input v-model.number="business.businessMoney" style="width: 91%"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="申请人:" prop="employeeByEmpId.empName">
                <el-input :disabled="true"  v-model="business.employeeByEmpId.empName" style="width: 79%"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="状态:">
                <el-select v-model="business.businessClassify" placeholder="未选" style="width: 79%">
                  <el-option v-for="item in ccOptions" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label="备注:">
                <el-input v-model="business.businessRemarks"  style="width: 91%"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label="审批状态:" style="width: 91%">
                <div v-if="this.business.businessId !== 0">
                  <div v-if="this.business.businessAppStatus === 0">
                    <span>待申请</span>
                    <el-tooltip class="item" effect="dark" content="待申请" placement="bottom">
                      <i class="el-icon-more font-18"></i>
                    </el-tooltip>
                  </div>
                  <div v-if="this.business.businessAppStatus === 1">
                    <span>待审批</span>
                    <el-tooltip class="item" effect="dark" content="待审批" placement="bottom">
                      <i class="el-icon-s-opportunity font-18"></i>
                    </el-tooltip>
                  </div>
                  <div v-if="this.business.businessAppStatus === 2">
                    <span>同意</span>
                    <el-tooltip class="item" effect="dark" content="同意" placement="bottom">
                      <i class="el-icon-circle-check font-18"></i>
                    </el-tooltip>
                    <span>审批人：{{business.employeeByEmpId.empName}}</span>
                  </div>
                  <div v-if="this.business.businessAppStatus === 3">
                    <span>否决</span>
                    <el-tooltip class="item" effect="dark" content="否决" placement="bottom">
                      <i class="el-icon-circle-close font-18"></i>
                    </el-tooltip>
                    <span>审批人：{{business.employeeByEmpId.empName}}</span>
                  </div>
                </div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label="审批记录:" style="width: 91%">
                <el-row></el-row>
                <el-row :key="index" v-for="(app,index) in approvalRecordList">
                  <div class="border-bo" >
                    <div class="font-13-bold">
                      <span>申请：</span>
                      <span class="margin-r-3">{{app.employeeByApplicantEmpId.empName}}<i class="el-icon-right"/> boss用户</span>
                      <span>{{app.approvalRecordDate | formatDateJudge}}</span>
                    </div>
                    <div class="font-13" v-if="app.employeeByApprovalEmpId !== null">
                      <span class="margin-r-3"><i class="el-icon-minus"/>{{app.employeeByApprovalEmpId.empName}}</span>
                      <span class="margin-r-3">{{app.approvalRecordTime | formatDate}}</span>
                      <span class="margin-r-3">{{app.approvalRecordOper}}</span>
                      <span>备注：{{app.approvalRecordNote}}</span>
                    </div>
                  </div>
                </el-row>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12" :offset="7">
              <el-form-item>
                <el-button @click="addBusiness" type="primary">保存</el-button>
                <el-button @click="dialogFormVisible = false">取消</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <!--内层dialog-->
        <el-dialog width="30%" title="全部客户" :visible.sync="innerDialog" append-to-body>
          <!--选择客户-->
          <el-table :data="customerList" style="width: 100%">
            <el-table-column prop="customerId" label="客户编号" >
            </el-table-column>
            <el-table-column prop="customerName" label="客户名" >
            </el-table-column>
            <el-table-column label="请选择" >
              <template slot-scope="scope">
                <el-button size="mini" @click="choiceCustomer(scope.row)" icon="el-icon-check" type="primary" circle style="margin-left: 10px"></el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-row style="margin-top:10px">
            <el-col :span="16">
              <el-pagination layout="prev, pager, next, jumper" :total="cusTotalSize" @current-change="cusChangePage"
                             :current-page.sync="cusCurrPage" :page-size="cusPageSize"></el-pagination>
            </el-col>
          </el-row>
        </el-dialog>
      </el-dialog>
    </el-row>
    <!--出差表格-->
    <el-table ref="multipleTable" :data="businessList" tooltip-effect="dark" id="outTable"
              style="width: 100%" :header-cell-style="rowClass" @selection-change="handleSelectionChange" border>
      <el-table-column type="selection" ></el-table-column>
      <el-table-column prop="businessId" label="ID" sortable></el-table-column>
      <el-table-column label="主题" >
        <template slot-scope="scope">
          <router-link :to="{path:'/businessview',query: {businessId: scope.row.businessId}}">
            <div style="color: #333333">
              <i class="el-icon-caret-right"></i>
              <span>{{scope.row.businessTheme}}</span>
            </div>
          </router-link>
        </template>
      </el-table-column>
      <el-table-column prop="employeeByEmpId.empName" label="申请人" ></el-table-column>
      <el-table-column prop="businessDestination" label="目的地" ></el-table-column>
      <el-table-column label="客户" >
        <template slot-scope="scope">
          <div style="color: #333333">
            <span>{{scope.row.customerByCustomerId.customerName}}</span>
            <el-tooltip class="item" effect="dark" content="打开详细页面" placement="bottom">
              <router-link :to="{path:'/customerview',query: {customerId: scope.row.customerByCustomerId.customerId}}">
                <span style="color: #333333">
                  <i class="el-icon-s-cooperation"></i>
                </span>
              </router-link>
            </el-tooltip>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="businessStartDate" label="开始时间" sortable>
        <template slot-scope="scope">
          <span>{{scope.row.businessStartDate | formatDateJudge}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="businessEndDate" label="结束时间" sortable>
        <template slot-scope="scope">
          <span>{{scope.row.businessEndDate | formatDateJudge}}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" >
        <template slot-scope="scope">
          <span v-if="scope.row.businessClassify === 1">{{ccOptions[0].label}}</span>
          <span v-if="scope.row.businessClassify === 2">{{ccOptions[1].label}}</span>
          <span v-if="scope.row.businessClassify === 3">{{ccOptions[2].label}}</span>
          <span v-if="scope.row.businessClassify === 4">{{ccOptions[3].label}}</span>
        </template>
      </el-table-column>
      <el-table-column label="审批状态" >
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" content="待申请" placement="bottom">
            <span class="font-18" v-if="scope.row.businessAppStatus === 0"><i class="el-icon-more"></i></span>
          </el-tooltip>
          <el-tooltip class="item" effect="dark" content="待审" placement="bottom">
            <span class="font-18" v-if="scope.row.businessAppStatus === 1"><i class="el-icon-s-opportunity"></i></span>
          </el-tooltip>
          <el-tooltip class="item" effect="dark" content="同意" placement="bottom">
            <span class="font-18" v-if="scope.row.businessAppStatus === 2"><i class="el-icon-circle-check"></i></span>
          </el-tooltip>
          <el-tooltip class="item" effect="dark" content="否决" placement="bottom">
            <span class="font-18" v-if="scope.row.businessAppStatus === 3"><i class="el-icon-circle-close"></i></span>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column prop="" label="操作" width="110px">
        <template slot-scope="scope">
          <div v-if="scope.row.businessAppStatus !== 2">
            <el-tooltip class="item" effect="dark" content="编辑" placement="bottom">
              <el-button size="mini" @click="handleEdit(scope.row)"
                         icon="el-icon-edit" type="primary" circle style="margin-left: 10px"></el-button>
            </el-tooltip>
            <el-tooltip class="item" effect="dark" content="删除" placement="bottom">
              <el-button size="mini" @click="handleDelete(scope.row)"
                         icon="el-icon-delete" type="danger" circle></el-button>
            </el-tooltip>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-row style="margin-top:10px">
      <el-col :span="8">
        <el-tooltip class="item" effect="dark" content="删除" placement="bottom">
          <el-button style="padding: 12px 12px" icon="el-icon-delete" @click="handleDeleteMany" type="danger"></el-button>
        </el-tooltip>
      </el-col>
      <el-col :span="13">
        <el-pagination layout="sizes,prev,pager, next, jumper" :total="totalSize" @current-change="changePage"
                       :current-page.sync="currPage" :page-size="pageSize" :page-sizes="pageSizes" @size-change="changeSize"></el-pagination>
      </el-col>
      <el-col :span="3">
        <el-tooltip class="item" effect="dark" content="打印列表" placement="bottom">
          <el-button @click="handleWindowPrint('#outTable', '列表打印')" style="padding: 12px 12px" type="info" plain  icon="el-icon-printer"></el-button>
        </el-tooltip>
        <el-tooltip class="item" effect="dark" content="批量导出Excel格式数据" placement="bottom">
          <el-button @click="batchExportExcel" style="padding: 12px 12px" type="info" plain  icon="el-icon-document-copy"></el-button>
        </el-tooltip>
        <el-tooltip class="item" effect="dark" content="导出Excel格式数据" placement="bottom">
          <el-button @click="exportExcel" style="padding: 12px 12px" type="info" plain  icon="el-icon-document-remove"></el-button>
        </el-tooltip>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import {formatTimeToStr} from "../assets/format";
  import XLSX from "xlsx";
  import FileSaver from "file-saver";
  export default {
  data () {
    return {
      emp:{},
      dialogFormVisible: false,
      businessList: [], // 出差集合分页
      customerList: [], // 客户集合
      pageSize: 10, // 分页页大小
      pageSizes:[10,20,30],//页大小数组
      currPage: 1, // 当前页码，默认为1
      totalSize: 0, // 总记录数
      cusPageSize: 5, // 选择客户-分页页大小
      cusCurrPage: 1, // 选择客户-当前页码，默认为1
      cusTotalSize: 0, // 选择客户-总记录数
      business: {
        businessId: 0,
        businessTheme: '',
        businessStartDate: '',
        businessEndDate: '',
        businessDestination: '',
        businessVehicle: '',
        businessMoney: '',
        businessClassify: '',
        businessRemarks: '',
        businessPeer: '',
        businessAppStatus: 0,
        customerByCustomerId:{},
        employeeByEmpId:'',
        employeeByAppEmpId:null,
        opportunityByOppId:null
      },
      approvalRecordList:[],// 审批记录集合
      customerBoxShow: true, // 客户搜索显示
      innerDialog: false,// 内层dialog客户
      innerDialogEmp: false,// 内层dialog员工
      content: '',// input内容
      customerValue:'',// 模糊查询客户查询值
      customerList2:[],// 模糊查询客户集合
      visible: false,// 模糊搜索ul显示
      rules: {
        businessTheme: [{
          required: true,
          message: '必须填',
          trigger: 'blur'
        }, {
          min: 2,
          max: 8,
          message: '长度在 2 到 15 个字符',
          trigger: 'blur'
        }],
        'customerByCustomerId.customerName': [
          { required: true, message: '请选择客户', trigger: 'blur' }
        ],
        'employeeByEmpId.empName': [
          { required: true, message: '请选择负责人', trigger: 'blur' }
        ],
        businessMoney: [
          { required: true, message: '必须填'},
          { type: 'number', message: '必须为数字'}
        ]
      },
      mulSelection: [],
      filterOptions: [{
        value: 0,
        label: '全部数据'
      }, {
        value: 1,
        label: '未出差'
      }, {
        value: 2,
        label: '出差中'
      }, {
        value: 3,
        label: '出差完成'
      }],
      filterValue: 0,
      ccOptions: [{
        value: 1,
        label: '未出差'
      }, {
        value: 2,
        label: '出差中'
      }, {
        value: 3,
        label: '出差完成'
      }],
      jtOptions: [{
        value: 1,
        label: '高铁'
      }, {
        value: 2,
        label: '动车'
      }, {
        value: 3,
        label: '火车'
      }, {
        value: 4,
        label: '飞机'
      }, {
        value: 5,
        label: '汽车'
      }, {
        value: 6,
        label: '其他'
      }],
      vagueOptions: [{
        value: 1,
        label: '出差主题'
      }, {
        value: 2,
        label: '客户名称'
      }],
      vagueValue: 1,
      selectList:[]
    }
  },
  methods: {
    // 查询当前员工
    loginEmp(){
      this.$axios.get('http://localhost:8088/emp')
        .then(v => {
          this.emp = v.data
        })
        .catch(function (v) {})
    },
    // 分页查询所有
    initData (currPage, pageSize,filter,vague,content) {
      this.$axios.get('http://localhost:8088/business-list', {
        params: {
          page: currPage,
          size: pageSize,
          filter:filter,
          vague:vague,
          content:content
        }
      })
        .then(v => {
          this.businessList = v.data.rows
          this.totalSize = v.data.total
        })
        .catch(function (v) {})
    },
    // 出差表格分页
    changePage (val) {
      this.initData(val, this.pageSize,this.filterValue,this.vagueValue,this.content)
    },
    //改变页大小
    changeSize(val){
      this.pageSize = val
      this.currPage = 1
      this.initData(this.currPage,this.filterValue,this.vagueValue,this.content)
    },
    // 查询报价单审批记录集合
    findAppRecord(busId){
      this.$axios.get('http://localhost:8088/app-record-bus-list', {
        params:{
          businessId : busId
        }
      })
        .then(v => {
          this.approvalRecordList = v.data
        })
        .catch(function (v) {})
    },
    // 修改数据回显
    handleEdit (val) {
      this.dialogFormVisible = true
      this.business.businessId = val.businessId
      this.business.businessTheme = val.businessTheme
      this.business.businessStartDate = val.businessStartDate
      this.business.businessEndDate = val.businessEndDate
      this.business.businessDestination = val.businessDestination
      this.business.businessVehicle = val.businessVehicle
      this.business.businessMoney = val.businessMoney
      this.business.businessClassify = val.businessClassify
      this.business.businessRemarks = val.businessRemarks
      this.business.businessPeer = val.businessPeer
      this.business.customerByCustomerId = val.customerByCustomerId
      this.business.employeeByEmpId = val.employeeByEmpId
      this.business.businessAppStatus = val.businessAppStatus
      this.business.employeeByAppEmpId = val.employeeByAppEmpId
      this.business.opportunityByOppId = val.opportunityByOppId
      this.findAppRecord(val.businessId)
      this.customerBoxShow = false
    },
    // 打开dialog事件
    openDialog () {
      if (this.business.businessId === 0){
        this.business.employeeByEmpId = this.emp
        this.business.businessClassify = 1
      }
    },
    // 关闭dialog事件
    closeDialog () {
      this.$refs.bus.resetFields()
      this.business = {
        businessId: 0,
        businessTheme: '',
        businessStartDate: '',
        businessEndDate: '',
        businessDestination: '',
        businessVehicle: '',
        businessMoney: '',
        businessClassify: '',
        businessRemarks: '',
        businessPeer: '',
        businessAppStatus: 0,
        customerByCustomerId: {},
        employeeByEmpId: '',
        employeeByAppEmpId: null,
        opportunityByOppId: null
      }
      this.approvalRecordList = []
      this.customerBoxShow = true
      this.contactList = []
    },
    // 新增、修改
    addBusiness () {
      this.$refs.bus.validate((valid) => {
        if (valid) {
          this.$axios.post('http://localhost:8088/save-business',this.business)
            .then(v => {
              this.initData(this.currPage,this.pageSize,this.filterValue,this.vagueValue,this.content)
              this.dialogFormVisible = false
              this.$message({
                type: 'success',
                message: '已保存'
              })
            })
            .catch(function (v) {})
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    // 打开内层dialog
    innerVisible (cusCurrPage,cusPageSize) {
      this.$axios.get('http://localhost:8088/emp-customer-list', {
        params: {
          page: cusCurrPage,
          size: cusPageSize,
        }
      })
        .then(v => {
          this.customerList = v.data.rows
          this.cusTotalSize = v.data.total
        })
        .catch(function (v) {})
      this.innerDialog = true
    },
    // 查询客户分页
    cusChangePage (val) {
      // val就是当前页码
      this.innerVisible(val, this.cusPageSize)
    },
    // 选择客户
    choiceCustomer(val){
      this.business.customerByCustomerId = val
      this.innerDialog = false;
    },
    // 模糊查询客户
    findCustomer(){
      if (this.customerValue !== ''){
        this.visible = true
        this.$axios.get('http://localhost:8088/emp-fuzzy-customer-list', {
          params: {
            customerName: this.customerValue
          }
        })
          .then(v => {
            this.customerList2 = v.data
          })
          .catch(function (v) {})
      }else {
        this.visible = false
      }
    },
    // 模糊选择客户
    choiceCustomer2(val){
      this.business.customerByCustomerId = val
      this.customerValue = ''
      this.visible = false
    },
    // 失去焦点关闭模糊搜索框
    cleanCustomer(){
      this.visible = false
      this.customerValue = ''
    },
    // 点击编辑详单跳转到出差视图
    openPro(busId){
      this.$router.push({path:'/quotationview',query: {busId: busId}});
    },
    // 删除提示
    handleDelete (val) {
      this.$confirm('此操作将永久删除该出差, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deleteBus(val.businessId)
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    // 批量删除提示
    handleDeleteMany () {
      this.$confirm('此操作将永久删除勾选出差, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deleteAll()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    // 获取批量删除对象集合
    handleSelectionChange (val) {
      this.mulSelection = val
    },
    // 删除axios
    deleteBus(businessId){
      this.$axios.post('http://localhost:8088/delete-business', this.qs.stringify({businessId: businessId}))
        .then(v => {
          this.initData(this.currPage,this.pageSize,this.filterValue,this.vagueValue,this.content)
        })
        .catch(function (v) {})
    },
    // 删除所有
    deleteAll () {
      this.mulSelection.forEach(row => {
        if(row.businessAppStatus === 2){
          this.$refs.multipleTable.clearSelection();
          this.$message({
            type: 'info',
            message: 'ID为'+row.businessId+'的数据已审核通过，无法删除'
          })
        }else {
          this.deleteBus(row.businessId)
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
        }

      })
    },
    // pdf打印
    handleWindowPrint (ele, fileName) {
      document.body.innerHTML = document.querySelector(ele).outerHTML
      // 转异步 等待dom元素渲染（样式）完毕在打印
      setTimeout(() => {
        // 打印
        window.print()
        // 刷新页面
        window.location.reload()
      }, 20)
    },
    //导出全部excel
    exportExcel () {
      var xlsxParam = { raw: true };//转换成excel时，使用原始的格式
      var wb = XLSX.utils.table_to_book(document.querySelector("#outTable"),xlsxParam);
      var wbout = XLSX.write(wb, {
        bookType: "xlsx",
        bookSST: true,
        type: "array"
      });
      try {
        FileSaver.saveAs(
          new Blob([wbout], { type: "application/octet-stream;charset=utf-8" }),
          "出差导出.xlsx"
        );
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
      }
      return wbout;
    },
    //批量导出excel batchList
    batchExportExcel(){
      this.mulSelection.forEach((item,i)=>{
        this.$set(item,'businessId',item.businessId);
        this.$set(item,'businessTheme',item.businessTheme);
        this.$set(item,'empName',item.employeeByEmpId.empName);
        this.$set(item,'businessDestination',item.businessDestination);
        this.$set(item,'customerName',item.customerByCustomerId.customerName);
        this.$set(item,'businessStartDate',formatTimeToStr(item.businessStartDate, 'yyyy-MM-dd'));
        this.$set(item,'businessEndDate',formatTimeToStr(item.businessEndDate, 'yyyy-MM-dd'));
        if (item.businessClassify !== null){
          this.$set(item,'businessClassify',this.ccOptions[item.businessClassify - 1].label);
        }
        if (item.businessVehicle !== null){
          this.$set(item,'businessVehicle',this.jtOptions[item.businessVehicle - 1].label);
        }
        this.selectList.splice(i,0,item);
      })
      //excel数据导出
      require.ensure([], () => {
        const {
          export_json_to_excel
        } = require('../js/Export2Excel');
        const tHeader = ['ID','主题','申请人','目的地','客户','开始时间','结束时间', '状态', '交通'];
        const filterVal = ['businessId','businessTheme','empName','businessDestination', 'customerName', 'businessStartDate','businessEndDate',
          'businessClassify', 'businessVehicle',];
        const list = this.selectList;
        const data = this.formatJson(filterVal, list);
        export_json_to_excel(tHeader, data, '出差导出');
      })
      this.initData(this.currPage,this.pageSize,this.filterValue,this.vagueValue,this.content)
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => v[j]))
    },
    // 表头靠左样式
    rowClass(){
      return "text-align:left"
    }
  },
    created() {
      this.loginEmp()
      this.initData(this.currPage,this.pageSize,this.filterValue,this.vagueValue,this.content)
    },
    filters: {
      formatDate: function(time) {
        if(time!=null&&time!="")
        {
          var date = new Date(time);
          return formatTimeToStr(date, "yyyy-MM-dd hh:mm");
        }else{
          return "";
        }
      },
      formatDateJudge: function(time) {
        if(time != null && time != "")
        {
          let date = new Date(time);
          let currentDate = new Date()
          let seperator1 = "-";
          let month = currentDate.getMonth() + 1<10? "0"+(currentDate.getMonth() + 1):currentDate.getMonth() + 1;
          let strDate = currentDate.getDate()<10? "0" + currentDate.getDate():currentDate.getDate();
          let today = currentDate.getFullYear() + seperator1  + month  + seperator1  + strDate
          let todayTime = new Date(today)
          let yesterday = todayTime.setDate(todayTime.getDate() - 1)
          let beforeYesterday = todayTime.setDate(todayTime.getDate() - 1)
          let tomorrow = todayTime.setDate(todayTime.getDate() + 3)
          let afterTomorrow = todayTime.setDate(todayTime.getDate() + 1)
          todayTime.setDate(todayTime.getDate() - 2)
          if (date.getTime() === todayTime.getTime()){
            return '今天'
          }else if (date.getTime() ===  yesterday){
            return '昨天'
          }else if (date.getTime() ===  beforeYesterday){
            return '前天'
          }else if (date.getTime() ===  tomorrow){
            return '明天'
          }else if (date.getTime() ===  afterTomorrow){
            return '后天'
          }else {
            return time
          }
        }else{
          return "";
        }
      }
    }
}
</script>

<style>
</style>
